﻿@using Digital.Common.Mvc.Extensions
@{
    ViewBag.Title = "账户信息管理";
    Layout = "~/Views/Shared/_LayoutDigital.cshtml";
}

@section PageSpecificJavascriptIncludes{
    <link rel="stylesheet" href="../DigitalStyle/css/jquery.gritter.css" />
    <link rel="stylesheet" href="../DigitalStyle/css/prettyPhoto.css" />

    <script src="../DigitalStyle/js/jquery.gritter.min.js"></script>
    <script src="../DigitalStyle/js/jquery.validate.min.js"></script>
    <script src="../DigitalStyle/js/JqueryToken.js"></script>
    <script src="../DigitalStyle/js/jquery.autogrow-textarea.js"></script>
    <script src="../DigitalStyle/js/messages_cn.js"></script>

    <script src="../DigitalStyle/js/jquery.prettyPhoto.js"></script>
}

<div class="pageheader">
    <h2><i class="fa fa-user"></i> 案例总览 <span>案例信息</span></h2>
    <div class="breadcrumb-wrapper">
        <span class="label">你的位置:</span>
        <ol class="breadcrumb">
            <li><a href="">企业中心</a></li>
            <li class="active">企业信息</li>
        </ol>
    </div>
</div>

<div class="contentpanel">
    <div class="row">
        <div class="contentpanel">

            <ul class="filemanager-options">
                <li>
                    <div class="ckbox ckbox-default">
                        <input type="checkbox" id="selectall" value="1" />
                        <label for="selectall">全选</label>
                    </div>
                </li>
                <li>
                    <a href="CompanyCasesAdd"><i class="fa fa-pencil"></i> 添加案例</a>
                </li>
                <li>
                    <a href="javascript:DeleteSelects()" class="itemopt disabled"><i class="fa fa-pencil"></i> 删除案例</a>
                </li>
                <li class="filter-type col-sm-4">

                    <select id="CasesCategory" class="form-control chosen-select" data-placeholder="选择分类..."></select>

                </li>

            </ul>



            <div class="row">
                <div class="col-sm-12">
                    @Html.AntiForgeryToken()
                    <div class="row filemanager">
                        @{
                            if (ViewBag.CaseList != null)
                            {
                                foreach (Digital.WCFClient.ConfigService.CasesModel Detail in ViewBag.CaseList)
                                {
                                    if (Detail != null)
                                    {
                                        <div class="col-xs-6 col-sm-4 col-md-3 document">
                                            <div class="thmb">
                                                <div class="ckbox ckbox-default">
                                                    <input type="checkbox" id="check@{@Detail.CasesID}" value="@Detail.CasesID" />
                                                    <label for="check@{@Detail.CasesID}"></label>
                                                </div>
                                                <div class="btn-group fm-group">
                                                    <button type="button" class="btn btn-default dropdown-toggle fm-toggle" data-toggle="dropdown">
                                                        <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu fm-menu" role="menu">
                                                        <li><a href="CompanyCasesAdd?Id=@Detail.CasesID"><i class="fa fa-pencil"></i> 编辑</a></li>
                                                        <li><a href="javascript:Delete(@Detail.CasesID)"><i class="fa fa-trash-o"></i> 删除</a></li>
                                                    </ul>
                                                </div><!-- btn-group -->
                                                <div class="thmb-prev">
                                                    <img src="@Html.IsNull(Detail.CasesThumbnail, "../DigitalStyle/images/photos/media-doc.png", Detail.CasesThumbnail)" class="img-responsive" alt="" />
                                                </div>
                                                <h5 class="fm-title"><a href="">@Detail.CasesName</a></h5>
                                                <small class="text-muted">@Detail.CasesDate.ToString()</small>
                                            </div><!-- thmb -->
                                        </div><!-- col-xs-6 -->
                                    }
                                }
                            }
                        }
                        <!-- col-xs-6 -->
                    </div><!-- row -->
                </div><!-- col-sm-9 -->

            </div>
        </div>


    </div>
</div>

<script>

    function callBack() {
        window.location = window.location;
    }

    function Delete(Id) {
        ComAjax("/Company/CompanyCasesDelete", { CasesId: Id }, "分类删除", "callBack");
    }

    function DeleteSelects() {
        var Ids = '';
        jQuery('.ckbox').each(function () {
            var t = jQuery(this);
            if (t.find('input').attr('id') != "selectall") {
                if (t.find('input').is(':checked')) {
                    Ids += t.find('input').val() + ",";
                }
            }
        });
        ComAjax("/Company/CompanyCasesDeleteAll", { CasesIds: Ids }, "分类删除", "callBack");
    }


    jQuery(document).ready(function () {
        // Chosen Select
        var CasesCategoryjsons =@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject((List<Digital.WCFClient.ConfigService.BaseNameValueMode>)ViewBag.CasesCategory))
        DropOption(CasesCategoryjsons, $("#CasesCategory"), 0);
        jQuery(".chosen-select").chosen({ 'width': '100%', 'white-space': 'nowrap' });

        jQuery('.thmb').hover(function () {
            var t = jQuery(this);
            t.find('.ckbox').show();
            t.find('.fm-group').show();
        }, function () {
            var t = jQuery(this);
            if (!t.closest('.thmb').hasClass('checked')) {
                t.find('.ckbox').hide();
                t.find('.fm-group').hide();
            }
        });

        jQuery('.ckbox').each(function () {
            var t = jQuery(this);
            var parent = t.parent();
            if (t.find('input').is(':checked')) {
                t.show();
                parent.find('.fm-group').show();
                parent.addClass('checked');
            }
        });


        jQuery('.ckbox').click(function () {
            var t = jQuery(this);
            if (!t.find('input').is(':checked')) {
                t.closest('.thmb').removeClass('checked');
                enable_itemopt(false);
            } else {
                t.closest('.thmb').addClass('checked');
                enable_itemopt(true);
            }
        });

        jQuery('#selectall').click(function () {
            if (jQuery(this).is(':checked')) {
                jQuery('.thmb').each(function () {
                    jQuery(this).find('input').attr('checked', true);
                    jQuery(this).addClass('checked');
                    jQuery(this).find('.ckbox, .fm-group').show();
                });
                enable_itemopt(true);
            } else {
                jQuery('.thmb').each(function () {
                    jQuery(this).find('input').attr('checked', false);
                    jQuery(this).removeClass('checked');
                    jQuery(this).find('.ckbox, .fm-group').hide();
                });
                enable_itemopt(false);
            }
        });

        function enable_itemopt(enable) {
            if (enable) {
                jQuery('.itemopt').removeClass('disabled');
            } else {

                // check all thumbs if no remaining checks
                // before we can disabled the options
                var ch = false;
                jQuery('.thmb').each(function () {
                    if (jQuery(this).hasClass('checked'))
                        ch = true;
                });

                if (!ch)
                    jQuery('.itemopt').addClass('disabled');
            }
        }

        //Replaces data-rel attribute to rel.
        //We use data-rel because of w3c validation issue
        jQuery('a[data-rel]').each(function () {
            jQuery(this).attr('rel', jQuery(this).data('rel'));
        });

        jQuery("a[rel^='prettyPhoto']").prettyPhoto();

    });

</script>